/* 
 * cms，一个基于J2EE架构内容管理系统
 * Copyright © GrayRabbit Co., Ltd. All rights reserved.
 * Department:运营department
 * 更多信息请访问：
 * http://code.google.com/p/gray-rabbit-cms/
 */
package org.grayrabbit.cms.action.topic;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.grayrabbit.cms.action.common.BaseAction;
import org.grayrabbit.cms.constant.ConstantOperCode;
import org.grayrabbit.cms.constant.ConstantWebApp;
import org.grayrabbit.cms.constant.DictionaryStaticValues;
import org.grayrabbit.cms.constant.ConstantEnum.Module;
import org.grayrabbit.cms.constant.ConstantEnum.OperAct;
import org.grayrabbit.cms.entity.Admin;
import org.grayrabbit.cms.entity.Content;
import org.grayrabbit.cms.entity.Dictionary;
import org.grayrabbit.cms.entity.Site;
import org.grayrabbit.cms.entity.Topic;
import org.grayrabbit.cms.service.dictionary.DictionaryService;
import org.grayrabbit.cms.service.system.AdminOperRelaService;
import org.grayrabbit.cms.service.system.AdminService;
import org.grayrabbit.cms.service.system.RoleOperRelaService;
import org.grayrabbit.cms.service.topic.TopicService;
import org.grayrabbit.cms.util.FilePathSptUtil;
import org.grayrabbit.cms.vo.topic.TopicBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import org.grayrabbit.dao.util.Page;

/**
 * <b>TopicAction</b> Struts2 action�?





 * @version 1.0,创建时间:2011-05-16 15:59:25 
 */
@Controller
@Scope("prototype")
@Results( {
		@Result(name = "reload", type = "redirect", location = "topic-list"),
		@Result(name = "input", type = "dispatcher", location = "topic-input.jsp"),
		@Result(name = "success", type = "dispatcher", location = "topic-list.jsp")
		}
		)
public class TopicAction extends BaseAction<TopicBean> {
	private static final long serialVersionUID = -1L;
	//Service接口接入
	@Autowired
	@Qualifier("topicServiceImpl")
	private TopicService topicService;
	//VO对象，由前端页面数据组装
	private TopicBean topic;
	private String orig;
	//批量操作时使用的传入的ID
	private String ids;
	private String adminName;
	private boolean tftopic;
	@Autowired
	@Qualifier("dictionaryServiceImpl")
	private DictionaryService dictionaryService;
	
	@Autowired
	@Qualifier("roleOperRelaServiceImpl")
	private RoleOperRelaService roleOperRelaService;
	@Autowired
	@Qualifier("adminOperRelaServiceImpl")
	private AdminOperRelaService adminOperRelaService;
	
	
	//VO对象，由前端页面数据组装
	private List<Dictionary> dicContentType;
	
	private List<Dictionary> dicIsTop;
	
	private List<Dictionary> dicAudit;
	private List<Dictionary> dicIsAudit;
	
	private String tname;
	private String oldSimpleName;
	public List<Dictionary> getDicContentType() {
		return dicContentType;
	}

	public void setDicContentType(List<Dictionary> dicContentType) {
		this.dicContentType = dicContentType;
	}

	public List<Dictionary> getDicIsTop() {
		return dicIsTop;
	}

	public void setDicIsTop(List<Dictionary> dicIsTop) {
		this.dicIsTop = dicIsTop;
	}

	public List<Dictionary> getDicAudit() {
		return dicAudit;
	}

	public void setDicAudit(List<Dictionary> dicAudit) {
		this.dicAudit = dicAudit;
	}
	public List <Content> contents;
	@Autowired
	@Qualifier("adminServiceImpl")
	private AdminService adminService;
	
	private List<Dictionary> dicTopicStatus;
	
	private List<Dictionary> dicIsEnable;
	
	
	
	public List<Dictionary> getDicIsEnable() {
		return dicIsEnable;
	}

	public void setDicIsEnable(List<Dictionary> dicIsEnable) {
		this.dicIsEnable = dicIsEnable;
	}

	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}
	
	public boolean isTftopic() {
		return tftopic;
	}

	public void setTftopic(boolean tftopic) {
		this.tftopic = tftopic;
	}

	public String getAdminName() {
		return adminName;
	}

	public void setAdminName(String adminName) {
		this.adminName = adminName;
	}

	public List<Dictionary> getDicTopicStatus() {
		return dicTopicStatus;
	}

	public String getOldSimpleName() {
		return oldSimpleName;
	}

	public void setOldSimpleName(String oldSimpleName) {
		this.oldSimpleName = oldSimpleName;
	}

	public void setDicTopicStatus(List<Dictionary> dicTopicStatus) {
		this.dicTopicStatus = dicTopicStatus;
	}

	/**return 前端页面数据组装VO对象,<b>TopicBean</b>*/
	public TopicBean getTopic() {
		return topic;
	}

	public void setTopic(TopicBean topic) {
		this.topic = topic;
	}
	
	public String getOrig() {
		return orig;
	}

	public void setOrig(String orig) {
		this.orig = orig;
	}

	//分页对象
	private Page<Topic> page = new Page<Topic>(MAX_PAGE_NUM,true);
	private Page<Content> contentPage = new Page<Content>(MAX_PAGE_NUM,true);
	/*
	 * 
	 * return分页对象，默认实例化。如：page.pageNu=2,将更新相应的对象property
	 */
	public Page<Topic> getPage() {
		return page;
	}
	public Page<Content> getContentPage() {
		return contentPage;
	}

	public void setContentPage(Page<Content> contentPage) {
		this.contentPage = contentPage;
	}

	//接收前端form,url提交参数组装成分页property
	public void setPage(Page<Topic> page) {
		this.page = page;
	}
	
	/**
	 * 获取数据字典KEY值对应的NAME
	 * 
	 * @param key
	 * @param type
	 *            数据字典类型
	 * @return
	 */
	public String getName(String key,String code) {
		return dictionaryService.getDictionaryByDictionaryKey(key,code).getDictionaryValue();
	}
	
	/**
	 * 在执行（struts2的action调用时）list()方法前执行本方法
	 */
	public void prepareList(){
		if(dictionaryService.getDictionaryListByTypeCode(DictionaryStaticValues.IS_ENABLE)!=null){
			dicIsEnable = dictionaryService.getDictionaryListByTypeCode(DictionaryStaticValues.IS_ENABLE);
		}
		if(dictionaryService.getDictionaryListByTypeCode(DictionaryStaticValues.TOPIC_STATUS)!=null){
			dicTopicStatus = dictionaryService.getDictionaryListByTypeCode(DictionaryStaticValues.TOPIC_STATUS);
		}
		if(dictionaryService.getDictionaryListByTypeCode(DictionaryStaticValues.CONTENT_STATUS)!=null){
			dicContentType = dictionaryService.getDictionaryListByTypeCode(DictionaryStaticValues.CONTENT_STATUS);
		}
		prepareModel();
	}
	
	/**
	 * 在执行任何其它action方法（struts2的action调用时）前执行本方法
	 */
	public void prepare(){
		if(topic==null){
			topic = new TopicBean();
		}
	}
	/**
	 * 实现ModelDriven的接口简例前端页的bean组装写法,
	 *  如：
	 *	<pre>
	 *		<code> name="user.userName"</code>
	 *	改写成：
	 *		<code> name="userName"</code>
	 *	action实例中，会自动组成user成员变量
	 *	</pre>
	 */
	public TopicBean getModel() {
		return topic;
	}
	
	@Override
	protected void prepareModel(){
		if(topic != null && StringUtils.isNotBlank(topic.getTopicId())){
			Topic item = topicService.getTopic(topic.getTopicId());
			topic = (TopicBean)dozer.map(item,TopicBean.class);
			topic.setSite(item.getSite());
		}
		
	}

	/**
	 * 删除<b>Topic</b>记录的方法，成员变量<b>key</b>为主键的String数组，以主键方式进行删作
	 * 删除成功后，返回"reload"，然后跳转到topic-list.action
	 */
	@SuppressWarnings("unused")
	@Override
	@Action(value="topic-delete",
			results={@Result(name="reload",type="redirectAction",params={"actionName","topic-list"})}
			)
	public String delete(){
		String text="yes";
		String  topicNames="";
		try{
		String[] idBatchs=getBatchIds();
		if(idBatchs != null){
			for(int j=0;j<idBatchs.length;j++){
				if(!authLicence(ConstantOperCode.TOPIC_TOPIC_EDIT, idBatchs[j])){
					text="sorroy";
					return renderText(text);
				}else{
					tftopic=false;
					for(String id : idBatchs){
						Topic topic = topicService.getTopic(id);
						topic=(TopicBean)dozer.map(topic, TopicBean.class);		
						contents=new ArrayList<Content>();
						contents=topicService.findByTopId(topic.getTopicId());
						if(contents.size()>0){
							tftopic=true;
							topicNames=topic.getTopicName()+";"+topicNames;
						}	
					}
					if(tftopic){
						text=topicNames;
						return renderText(text);
					}else{
						topicService.delete(idBatchs);
						roleOperRelaService.deleteObjectAuth(idBatchs,ConstantOperCode.AUTH_TOPIC_TYPE);
						adminOperRelaService.deleteObjectAuth(idBatchs,ConstantOperCode.AUTH_TOPIC_TYPE);
					}
					for(int i=0;i<idBatchs.length;i++){
						addLog(Module.TOPIC.getValue(),OperAct.DEL.getValue(),idBatchs[i]);
					}
					return renderText(text);
				}
			}
		
		}else{			
			contents=topicService.findByTopId(key[0]);	
			if(contents.size()==0){
				topicService.delete(key);
				roleOperRelaService.deleteObjectAuth(key,ConstantOperCode.AUTH_TOPIC_TYPE);
				adminOperRelaService.deleteObjectAuth(key,ConstantOperCode.AUTH_TOPIC_TYPE);
			}else{
				text="no";
				return renderText(text);
			}
			addLog(Module.TOPIC.getValue(),OperAct.DEL.getValue(),key[0]);
		}
		}catch(Exception e){
			LOG.info("-------删除报错");
		}
		return RELOAD;
	}
	
	/**
	 * Topic的列表方法，通过成员变量<b>page�?{insClassName}</b>调用service接口，更新page
	 * 执行成功后，将映射到topic-list.jsp页面
	 */
	@Override
	@Action(value="topic-list")
	public String list(){
		Site currentSite = (Site)getSessionValue(ConstantWebApp.CURRENT_SITE);
		if(currentSite!=null && StringUtils.isBlank(currentSite.getSiteId())){
			return ERROR;
		}
		topic.setSite(currentSite);
		if(StringUtils.isNotBlank(topic.getIsEnebleForPage())){
			topic.setIsEnable(topic.getIsEnebleForPage().equals("true")?true:false);
		}
		topicService.list(page,topic);
		return SUCCESS;
	}
	/**
	 * Topic的新增与编辑的方法执行成功能
	 * 将映射到topic-input.jsp
	 */
	@Action(value="topic-input")
	public String input(){
		if(dictionaryService.getDictionaryListByTypeCode(DictionaryStaticValues.TOPIC_STATUS)!=null){
			dicTopicStatus = dictionaryService.getDictionaryListByTypeCode(DictionaryStaticValues.TOPIC_STATUS);
		}
		if(dictionaryService.getDictionaryListByTypeCode(DictionaryStaticValues.IS_ENABLE)!=null){
			dicIsEnable = dictionaryService.getDictionaryListByTypeCode(DictionaryStaticValues.IS_ENABLE);
		}
		if(dictionaryService.getDictionaryListByTypeCode(DictionaryStaticValues.IS_AUDIT)!=null){
			dicIsAudit = dictionaryService.getDictionaryListByTypeCode(DictionaryStaticValues.IS_AUDIT);
		}
		prepareModel();
		if(topic != null && StringUtils.isNotBlank(topic.getTopicId())){
			List<Admin> list = adminService.AllAuditorAdmins(
					ConstantOperCode.AUTH_TOPIC_TYPE, topic.getTopicId());
			if(list != null && !list.isEmpty()){
				StringBuffer sb = new StringBuffer();
				int index = list.size() ;
				for(Admin a : list){
					sb.append(a.getLoginName());
					index -- ;
					if(index >0) sb.append(",");				
				}
				topic.setAuditor(sb.toString());
			}
		}
		return INPUT;
	}
	/**
	 * save or update Topic的方法，将成员property topic转成Topic实例，执行保存；
	 * 执行成功后，返回"reload"，然后跳转到topic-list.action
	 */
	@Override
	@Action(value="topic-save",
			results={@Result(name="reload",type="redirectAction",params={"actionName","topic-list"})}
		)
	public String save(){
		Admin login = getCurrentAdmin();
		Topic obj = null;
		Topic item = null;
		if(StringUtils.isNotBlank(topic.getTopicId())){
			 item = topicService.getTopic(topic.getTopicId());
			 obj = (Topic) dozer.map(topic, Topic.class);
			 obj.setSite(item.getSite());
		}else{
			 obj = (Topic) dozer.map(topic, Topic.class);
		}
		
		if(!StringUtils.isNotBlank(obj.getTopicId())){
			obj.setTopicId(null);
		}
		
		if(StringUtils.isNotBlank(orig) && "audit".equals(orig)){
			obj.setAuditTime(new Date());
			obj.setAuditLoginName(login.getLoginName());
			obj.setAuditRealName(login.getRealName());
		}
		
		Site currentSite = (Site)getSessionValue(ConstantWebApp.CURRENT_SITE);
		if(StringUtils.isBlank(topic.getTopicId())){
			obj.setIsEnable(true);
			obj.setIsAudit(true);
			obj.setTopicStatus("0");
			obj.setCreateTime(new Date());
			if(login != null){
				obj.setCreateLoginName(login.getLoginName());
				obj.setCreateRealName(login.getRealName());
			}
			obj.setSite(currentSite);
		}else{
			obj.setUpdateTime(new Date());
			if(login != null){
				obj.setUpdateLoginName(login.getLoginName());
				obj.setUpdateRealName(login.getRealName());
			}
		}
		String topicname = topic.getTopicName().trim();
		obj.setTopicName(topicname);
		String topicsimpname = topic.getTopicSimpleName().trim();
		obj.setTopicSimpleName(topicsimpname);
		topicService.save(obj);
		//创建 专题时给其赋予相应的权限
		if(StringUtils.isBlank(topic.getTopicId())){
			addObjectDistributeAuthCode(obj.getTopicId(),ConstantOperCode.AUTH_TOPIC_TYPE,ConstantOperCode.TOPIC_TOPIC_EDIT);
			addLog(Module.TOPIC.getValue(),OperAct.ADD.getValue(),obj.getTopicId());
		}else{
			addLog(Module.TOPIC.getValue(),OperAct.ADD.getValue(),topic.getTopicId());
		}
		String auditors = topic.getAuditor();
		distributeAuditAuthCode(obj.getTopicId(),ConstantOperCode.AUTH_TOPIC_TYPE,ConstantOperCode.TOPIC_DOC_AUDIT,auditors);
		return RELOAD;
	}
	
	/**
	 * 保存模板信息
	 * @return
	 */
	@Action(value="topic-savetpl")
	public String saveTpl(){
		String text = "";
		Topic obj=null;
		try {
			if(topic != null &&StringUtils.isNotBlank(topic.getTopicId())){
				obj= topicService.getTopic(topic.getTopicId());
				if(StringUtils.isNotBlank(topic.getTopicIndexTpl())){
					obj.setTopicIndexTpl((topic.getTopicIndexTpl()));
				}
				if(StringUtils.isNotBlank(topic.getTopicContextListTpl())){
					obj.setTopicContextListTpl((topic.getTopicContextListTpl()));
				}
				if(StringUtils.isNotBlank(topic.getTopicDefaultContentTpl())){
					obj.setTopicDefaultContentTpl((topic.getTopicDefaultContentTpl()));
				}
				if(StringUtils.isNotBlank(topic.getTopicContentTplSet())){
					obj.setTopicContentTplSet((topic.getTopicContentTplSet()));
				}
				topicService.save(obj);
				addLog(Module.TOPIC.getValue(),OperAct.ADD.getValue(),topic.getTopicId());
			}
			text="ok";
		} catch (Exception e) {
			log.debug(e.getMessage());
			text="no";
		}
		return renderText(text);
	}
	/**
	 * 根据站点Id查询专题列表
	 * @param siteId
	 * @return
	 */
	public List<Topic> findBySiteId(String siteId){
		Site currentSite = (Site)getSessionValue(ConstantWebApp.CURRENT_SITE);
		List<Topic> list = topicService.findBySiteId(currentSite.getSiteId());
		return list;
	}
	
	/**
	 * 禁用/启用 专题
	 * @return
	 */
	@Action(value="topic-disableorenable")
	public String disableOrEnable(){
		String text="";
		Topic obj=null;
		try {
			if(topic != null &&StringUtils.isNotBlank(topic.getTopicId())){
				obj= topicService.getTopic(topic.getTopicId());
				if(obj.getIsEnable() != null &&!obj.getIsEnable()){
					obj.setIsEnable(true);
					addLog(Module.TOPIC.getValue(),OperAct.ENABLE.getValue(),topic.getTopicId());
				}else{
					obj.setIsEnable(false);
					addLog(Module.TOPIC.getValue(),OperAct.DISABLE.getValue(),topic.getTopicId());
				}
				topicService.save(obj);
			}
			text="ok";
		} catch (Exception e) {
			log.debug(e.getMessage());
			text="no";
			
		}
		return renderText(text);
	}
	
	/**
	 *  审核、不审核
	 * @return
	 */
	@Action(value="topic-auditorno")
	public String auditOrNo(){
		String text="";
		Topic obj=null;
		try {
			if(topic != null &&StringUtils.isNotBlank(topic.getTopicId())){
				obj= topicService.getTopic(topic.getTopicId());
				if(obj.getIsAudit() != null &&!obj.getIsAudit()){
					obj.setIsAudit(true);
				}else{
					obj.setIsAudit(false);
				}
				topicService.save(obj);
				addLog(Module.TOPIC.getValue(),OperAct.ADUIT.getValue(),topic.getTopicId());
			}
			text="ok";
		} catch (Exception e) {
			log.debug(e.getMessage());
			text="no";
		}
		return renderText(text);
	}
	/**
	 * 批量操作，ID处理
	 * @return
	 */
	private String[] getBatchIds(){
		String[] idBatchs=null;
		if((ids != null)&&(StringUtils.isNotBlank(ids))){
			if(ids.contains("on")){
				idBatchs=ids.substring(3).split("@");
			}else{
				idBatchs=ids.split("@");
			}
		}
		return idBatchs;
	}
	/**
	 * 批量禁用
	 */
	@Action(value="topic-batchdisable")
	public String batchDisable(){
		String text="";
		try {
			String[] idBatchs=getBatchIds();
			for(int j=0;j<idBatchs.length;j++){
				if(!authLicence(ConstantOperCode.TOPIC_TOPIC_EDIT, idBatchs[j])){
					text="sorroy";
					break;
				}
				else{
					topicService.disable(idBatchs);
					for(int i=0;i<idBatchs.length;i++){
						addLog(Module.TOPIC.getValue(),OperAct.DISABLE.getValue(),idBatchs[i]);
					}
					text="ok";
				}
			}
			
			
		} catch (Exception e) {
			text="no";
			log.debug(e.getMessage());
		}
		return renderText(text);
	}
	/**
	 * 批量启用
	 */
	@Action(value="topic-batchenable")
	public String batchEnable(){
		String text="";
		try {
			String[] idBatchs=getBatchIds();
			for(int j=0;j<idBatchs.length;j++){
				if(!authLicence(ConstantOperCode.TOPIC_TOPIC_EDIT, idBatchs[j])){
					text = "sorry";
					break;
				}else{
					topicService.enable(idBatchs);
					for(int i=0;i<idBatchs.length;i++){
						addLog(Module.TOPIC.getValue(),OperAct.ENABLE.getValue(),idBatchs[i]);
					}
					text="ok";
				}
			}
		} catch (Exception e) {
			text="no";
			log.debug(text);
		}
		return renderText(text);
	}
	/**
	 * 批量 审核设置
	 */
	@Action(value="topic-batchaudit")
	public String batchAudit(){
		String text="";
		try {	
			String[] idBatchs=getBatchIds();
			for(int j=0;j<idBatchs.length;j++){
			    if(!authLicence(ConstantOperCode.TOPIC_TOPIC_EDIT, idBatchs[j])){
						text="sorroy";break;
				}
				else{
				  topicService.audit(idBatchs);
				  text="ok";
			    }
			}
		} catch (Exception e) {
			text="no";
			log.debug(text);
		}
		return renderText(text);
	}

	/**
	 * 批量 不审核设置
	 */
	@Action(value="topic-batchnoaudit")
	public String batchNoAudit(){
		String text="";
		try {
			String[] idBatchs=getBatchIds();
			for(int j=0;j<idBatchs.length;j++){
			    if(!authLicence(ConstantOperCode.TOPIC_TOPIC_EDIT, idBatchs[j])){
						text="sorroy";break;
				}
				else{
					topicService.noAudit(idBatchs);
					text="ok";
				}
		   }
		} catch (Exception e) {
			text="no";
			log.debug(text);
		}
		return renderText(text);
	}
	/**
	 * 查询审核人
	 * @return
	 */
	@Action(value="topic-authorsetselect")
	public String adminList(){
		List<Admin> list = adminService.getAllUsableAdmins();
		Map<String,Object> map =new HashMap<String,Object>(); 
		JSONObject json = new  JSONObject();
		JSONArray jsonArray = new JSONArray();
		for(int i=0;i<list.size();i++){
			map.put("adminId", list.get(i).getAdminId());
			map.put("loginName", list.get(i).getLoginName());
			map.put("realName",list.get(i).getRealName());
			json = JSONObject.fromObject( map ); 
			jsonArray.add(json);
		}
		return renderText(jsonArray.toString());
	}
	/**
	 * 设置审核人-save
	 * @return
	 */
	@Action(value="topic-authorset")
	public String authorSet(){
		String text="";
		String[] idBatchs=getBatchIds();
		if(idBatchs != null){
			for(int i=0;i<idBatchs.length;i++){
				if(!authLicence(ConstantOperCode.TOPIC_TOPIC_EDIT, idBatchs[i])){
					text="sorroy";
					return renderText(text);
				}
				Topic topicObj = topicService.getTopic(idBatchs[i]);
				topicObj.setAuditRealName(adminName);
				topicService.save(topicObj);
				distributeAuditAuthCode(topicObj.getTopicId(),ConstantOperCode.AUTH_TOPIC_TYPE,ConstantOperCode.TOPIC_DOC_AUDIT,adminName);
			}
		}else{
			Topic topicObj = topicService.getTopic(topic.getTopicId());
			topicObj.setAuditRealName(adminName);
			topicService.save(topicObj);
			distributeAuditAuthCode(topicObj.getTopicId(),ConstantOperCode.AUTH_TOPIC_TYPE,ConstantOperCode.TOPIC_DOC_AUDIT,adminName);
		}
		text = "ok";
		addLog(Module.TOPIC.getValue(),OperAct.DISABLE.getValue(),topic.getTopicId());
		return renderText(text);
	}
	/**
	 * 保存关键字
	 * @return
	 */
	@Action(value="topic-savekeywords")
	public String saveKeywords(){
		String text = "";
		Topic topicObj = topicService.getTopic(topic.getTopicId());
		try{
			String keywords = topic.getKeywords();
			//String keyws = new String(keywords.getBytes("ISO-8859-1"),"UTF-8");
			topicObj.setKeywords(keywords);
			topicService.save(topicObj);
			text = "yes";
		}catch(Exception e){
			text = "no";
			LOG.error("保存关键字异常", e);
			e.printStackTrace();
		}
		return renderText(text);
	}
		
	
	/**
	 * 专题名称唯一验证
	 * @return
	 */
	@Action(value="topic-checknameunique")
	public String  checkNameUnique(){
		if(topic != null && StringUtils.isNotBlank(topic.getTopicId())){
			Topic item = topicService.getTopic(topic.getTopicId());
			topic = (TopicBean)dozer.map(item,TopicBean.class);
			topic.setSite(item.getSite());
		}
		String text="";
		try{
			Site currentSite = (Site)getSessionValue(ConstantWebApp.CURRENT_SITE);
			Boolean unique=topicService.checkNameUnique(topic.getTopicName().trim(),tname,currentSite.getSiteId());
			if(!unique){
				text="ok";
			}else{
				text="no";
			}
		}catch(Exception e){
			LOG.error("专题名称唯一验证异常", e);
			e.printStackTrace();
			text="no";
		}
		return renderText(text);
	}
	/*
	 * 专题简称唯一验证
	 */
	@Action(value="topic-checkSimplenameunique")
	public String checkSimplenameunique(){
		if(topic != null && StringUtils.isNotBlank(topic.getTopicId())){
			Topic item = topicService.getTopic(topic.getTopicId());
			topic = (TopicBean)dozer.map(item,TopicBean.class);
			topic.setSite(item.getSite());
		}
		String text="";
		try {
			Site currentSite = (Site)getSessionValue(ConstantWebApp.CURRENT_SITE);
			Boolean unique=topicService.checkSimplenameunique(topic.getTopicSimpleName(), currentSite.getSiteId(), oldSimpleName);
			if(!unique){
				text="yes";
			}else{
				text="no";
			}
		} catch (Exception e) {
			 text="no";
			 LOG.error("专题简称唯一验证异常", e);
			 e.printStackTrace();
		}
		return renderText(text);
	}
	
	private String getParentName(Topic obj){
		StringBuffer text = new StringBuffer();
		Topic top = topicService.getTopic(obj.getTopicId());
		text.append(top.getTopicSimpleName());
		return text.toString();
	}
	
	/**
	 * 根据专题id获专题简称-判断是否可以静态预览
	 * @return
	 */
	@Action(value="category-getsimplename")
	public String getSimpleName(){
		Topic obj = null;
		obj = topicService.getTopic(topic.getTopicId());
		
		String text = getParentName(obj);
		String url = (obj.getSite().getSiteDomain()+FilePathSptUtil.URL_SPT+
				DictionaryStaticValues.TOPIC+FilePathSptUtil.URL_SPT+
				text.replace("@", FilePathSptUtil.URL_SPT)+"index.html");
		File file = new File(FilePathSptUtil.LOCAL_SITE_PUBLISH_PATH+
				obj.getSite().getSiteShortName()+FilePathSptUtil.padLeftSpt(
				DictionaryStaticValues.TOPIC)+FilePathSptUtil.padLeftSpt(
						text.replace("@", File.separator))+"index.html");
		if(file.exists()){
			return renderText("{flag:true,url:'"+url+"'}");
		}else{
			return renderText("{flag:false}");
		}
	}
	
	public String getTname() {
		return tname;
	}

	public void setTname(String tname) {
		this.tname = tname;
	}

	public List<Content> getContents() {
		return contents;
	}

	public void setContents(List<Content> contents) {
		this.contents = contents;
	}

	public List<Dictionary> getDicIsAudit() {
		return dicIsAudit;
	}

	public void setDicIsAudit(List<Dictionary> dicIsAudit) {
		this.dicIsAudit = dicIsAudit;
	}
	
}